<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>jenkins | Bruce Blog</title><meta name="author" content="Bruce Wong"><meta name="copyright" content="Bruce Wong"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="jenkisn集成三方组件测试报告：pytest-testreportpytest-testreport主页：https:&#x2F;&#x2F;gitee.com&#x2F;lemon-test-official&#x2F;pytest-testreport 与jenkins集成步骤  安装pytest-testreport：pip3 install pytest-testreport  jenkins安装插件：HTML Publis">
<meta property="og:type" content="article">
<meta property="og:title" content="jenkins">
<meta property="og:url" content="https://brucewong123.gitee.io/bruce-blog/2023/03/06/techlife/jenkins/index.html">
<meta property="og:site_name" content="Bruce Blog">
<meta property="og:description" content="jenkisn集成三方组件测试报告：pytest-testreportpytest-testreport主页：https:&#x2F;&#x2F;gitee.com&#x2F;lemon-test-official&#x2F;pytest-testreport 与jenkins集成步骤  安装pytest-testreport：pip3 install pytest-testreport  jenkins安装插件：HTML Publis">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://bruce-blog123.oss-cn-beijing.aliyuncs.com/blog/202303071830113.jpg">
<meta property="article:published_time" content="2023-03-06T07:47:24.000Z">
<meta property="article:modified_time" content="2023-03-07T10:32:02.608Z">
<meta property="article:author" content="Bruce Wong">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://bruce-blog123.oss-cn-beijing.aliyuncs.com/blog/202303071830113.jpg"><link rel="shortcut icon" href="/bruce-blog/img/favicon.png"><link rel="canonical" href="https://brucewong123.gitee.io/bruce-blog/2023/03/06/techlife/jenkins/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/bruce-blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/bruce-blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'jenkins',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-07 18:32:02'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/bruce-blog/archives/"><div class="headline">文章</div><div class="length-num">2</div></a><a href="/bruce-blog/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/bruce-blog/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bruce-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/techlife/"><i class="fa-fw fas fa-home"></i><span> 技术人生</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bruce-blog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bruce-blog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/bruce-blog/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bruce-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/bruce-blog/" title="Bruce Blog"><span class="site-name">Bruce Blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bruce-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/techlife/"><i class="fa-fw fas fa-home"></i><span> 技术人生</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bruce-blog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bruce-blog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/bruce-blog/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bruce-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bruce-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">jenkins</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-06T07:47:24.000Z" title="发表于 2023-03-06 15:47:24">2023-03-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-03-07T10:32:02.608Z" title="更新于 2023-03-07 18:32:02">2023-03-07</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="jenkins"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><h1 id="jenkisn集成三方组件"><a href="#jenkisn集成三方组件" class="headerlink" title="jenkisn集成三方组件"></a>jenkisn集成三方组件</h1><h2 id="测试报告：pytest-testreport"><a href="#测试报告：pytest-testreport" class="headerlink" title="测试报告：pytest-testreport"></a>测试报告：pytest-testreport</h2><p>pytest-testreport主页：<a target="_blank" rel="noopener" href="https://gitee.com/lemon-test-official/pytest-testreport">https://gitee.com/lemon-test-official/pytest-testreport</a></p>
<p><strong>与jenkins集成步骤</strong></p>
<ol>
<li><p>安装pytest-testreport：<code>pip3 install pytest-testreport</code></p>
</li>
<li><p>jenkins安装插件：<code>HTML Publisher</code></p>
</li>
<li><p>修改pytest的build脚本 &#x3D;&#x3D;&#x3D; 测试跑完后生成报告</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">/usr/bin/python3 -m pytest -vs --disable-warnings --report=<span class="variable">$BUILD_NUMBER</span>.html --template=1 --tester=Jenkins --title=haokan接口监控报告 </span><br></pre></td></tr></table></figure>
</li>
<li><p>修改pytest-testreport源码<br>去掉生成报告文件名里的时间戳，以便上一步中“${BUILD_NUMBER}.html”能找到对应文件</p>
<ol>
<li>进入：<code>cd /usr/local/python3/lib/python3.8/site-packages/pytestTestreport</code></li>
<li><code>vim pytest_testreport.py </code></li>
<li>注掉原有生成文件名时，插入时间戳代码</li>
</ol>
</li>
</ol>
<p> <img src="https://bruce-blog123.oss-cn-beijing.aliyuncs.com/blog/202303071751682.png" alt="image-20230307175157631">  </p>
<ol start="5">
<li>增加构建后操作，Publish HTML reports &#x3D;&#x3D;&#x3D; 让build结果页中带报告入口</li>
</ol>
<p> <img src="https://bruce-blog123.oss-cn-beijing.aliyuncs.com/blog/202303071753859.png" alt="image-20230307175354800">  </p>
<ol start="6">
<li><p>修改飞书配置 &#x3D;&#x3D;&#x3D; 失败后消息中，带报告链接</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;msg_type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;post&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;content&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;post&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;zh_cn&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Realme API Monitor MY&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;content&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">          <span class="punctuation">[</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">              <span class="attr">&quot;tag&quot;</span><span class="punctuation">:</span> <span class="string">&quot;text&quot;</span><span class="punctuation">,</span></span><br><span class="line">              <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;haokan锁屏接口监控构建失败: &quot;</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">              <span class="attr">&quot;tag&quot;</span><span class="punctuation">:</span> <span class="string">&quot;a&quot;</span><span class="punctuation">,</span></span><br><span class="line">              <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;构建（Build）地址：&quot;</span><span class="punctuation">,</span></span><br><span class="line">              <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span> <span class="string">&quot;$BUILD_URL&quot;</span></span><br><span class="line">            <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="punctuation">&#123;</span></span><br><span class="line">              <span class="attr">&quot;tag&quot;</span><span class="punctuation">:</span> <span class="string">&quot;a&quot;</span><span class="punctuation">,</span></span><br><span class="line">              <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;报告（Report）地址：&quot;</span><span class="punctuation">,</span></span><br><span class="line">              <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span> <span class="string">&quot;http://47.254.255.115:8080/job/hk_realme_monitor/$BUILD_NUMBER/haokan_e68ea5_e58fa3_e79b91_e68ea7_e68aa5_e5918a/&quot;</span></span><br><span class="line">            <span class="punctuation">&#125;</span></span><br><span class="line">          <span class="punctuation">]</span></span><br><span class="line">        <span class="punctuation">]</span></span><br><span class="line">      <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>修改系统配置 &#x3D;&#x3D;&#x3D; 让打开的页面可以显示css</p>
<figure class="highlight groovy"><table><tr><td class="code"><pre><span class="line">System.setProperty(<span class="string">&quot;hudson.model.DirectoryBrowserSupport.CSP&quot;</span>,<span class="string">&quot;&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>注意：在jenkins脚本控制台中执行，执行完需要重启</p>
</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://brucewong123.gitee.io/bruce-blog">Bruce Wong</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://brucewong123.gitee.io/bruce-blog/2023/03/06/techlife/jenkins/">https://brucewong123.gitee.io/bruce-blog/2023/03/06/techlife/jenkins/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://brucewong123.gitee.io/bruce-blog" target="_blank">Bruce Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/bruce-blog/2023/03/05/hello-world/" title="Hello World"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Hello World</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/bruce-blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Bruce Wong</div><div class="author-info__description">一个简单的博客</div></div><div class="card-info-data site-data is-center"><a href="/bruce-blog/archives/"><div class="headline">文章</div><div class="length-num">2</div></a><a href="/bruce-blog/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/bruce-blog/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#jenkisn%E9%9B%86%E6%88%90%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6"><span class="toc-number">1.</span> <span class="toc-text">jenkisn集成三方组件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E6%8A%A5%E5%91%8A%EF%BC%9Apytest-testreport"><span class="toc-number">1.1.</span> <span class="toc-text">测试报告：pytest-testreport</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/bruce-blog/2023/03/06/techlife/jenkins/" title="jenkins"><img src="https://bruce-blog123.oss-cn-beijing.aliyuncs.com/blog/202303071830113.jpg" onerror="this.onerror=null;this.src='/bruce-blog/img/404.jpg'" alt="jenkins"/></a><div class="content"><a class="title" href="/bruce-blog/2023/03/06/techlife/jenkins/" title="jenkins">jenkins</a><time datetime="2023-03-06T07:47:24.000Z" title="发表于 2023-03-06 15:47:24">2023-03-06</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bruce-blog/2023/03/05/hello-world/" title="Hello World">Hello World</a><time datetime="2023-03-04T16:10:42.081Z" title="发表于 2023-03-05 00:10:42">2023-03-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Bruce Wong</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/bruce-blog/js/utils.js"></script><script src="/bruce-blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>